import http from "@/utils/http";
import type {
  ProcessCustomerStage,
  ProcessParams,
  ProcessTaskItem,
  CustomerProfilingItem,
  CustomerStage,
  SystemConfig,
  BeforeTaskParams,
  BeforeTaskItem,
  financeSubjectsParams,
  LoanParams,
  InvoicesList,
  approves
} from "./type";

/**
 * 获取配置类参数
 */
export const getConfig = () => {
  return http.get("/crm/system/selectList");
};
/**
 * 设置配置类参数
 */
export const setConfig = (data: SystemConfig) => {
  return http.post("/crm/system/setParams", data);
};
/**
 * 业务类型列表
 */
export const getPortraitList = () => {
  return http.get<CustomerProfilingItem[]>("/crm/system/portraitList");
};
/**
 * 新增/修改业务类型
 */
export const updatePortrait = (data: CustomerProfilingItem) => {
  return http.post("/crm/system/portrait", data);
};
/**
 * 删除业务类型
 */
export const delPortrait = (id: string) => {
  return http.deleteMethod(`/crm/system/deletePortrait/${id}`);
};

/**
 * 获取客户阶段列表
 */
export const getStageList = () => {
  return http.get<CustomerStage[]>("/crm/system/stageList");
};

/**
 * 新增/修改客户阶段
 */
export const updateStage = (data: CustomerStage) => {
  return http.post("/crm/system/stage", data);
};
/**
 * 删除客户阶段
 */
export const delStage = (stageId: string) => {
  return http.deleteMethod(`/crm/system/deleteStage/${stageId}`);
};

/**
 * (流程配置)获取列表
 */
export const getFlowConfigList = (params: ProcessParams) => {
  return http.get("/crm/system/processTaskList", params);
};

/**
 * (流程配置)新增/修改客户阶段
 */
export const updateFlowStage = (data: ProcessCustomerStage) => {
  return http.post("/crm/system/insertStage", data);
};

/**
 * （流程配置）客户阶段列表
 */
export const getProcessStageList = () => {
  return http.get<CustomerStage[]>("/crm/system/stageOptions");
};
/**
 * (流程配置)添加/编辑流程
 */
export const updateFlow = (data: ProcessTaskItem) => {
  return http.post("/crm/system/insertProcessTask", data);
};

/**
 * 修改流程任务状态
 */
export const updateTaskStatus = (taskId: string) => {
  return http.put(`/crm/system/setStatus/${taskId}`);
};

/**
 * 获取前置流程选项列表
 */
export const getOptionList = (params: any) => {
  return http.get<BeforeTaskItem>("/crm/system/selectProcessTaskCheckBox", params);
};
/**
 * 删除流程
 */
export const deleteTask = (taskSettingId: string) => {
  return http.deleteMethod(`/crm/system/deleteTask/${taskSettingId}`);
};
/**
 * (流程配置)删除客户阶段
 */
export const deleteCstStage = (portraitStageId: string) => {
  return http.deleteMethod(`/crm/system/deleteCstStage/${portraitStageId}`);
};

/**
 * 文件上传
 */
export const uploadFile = (data: FormData) => {
  return http.post("/sass/file/upload", data);
};

/**
 * 查询全部表单
 */
export const getFormList = (formName: string) => {
  return http.get(`/crm/form/list?formName=${formName}`);
};
/**
 * 查询全部表单——下拉搜索组件
 */
export const getSelectFormList = (params: any) => {
  return http.get(`/crm/form/list`, params);
};

/**
 * 根据formId查询发布的表单字段
 */
export const formFieldByFormId = (formId: string, params?: { fieldName: string }) => {
  return http.get(`/process/model/publish/field/${formId}`, params);
};
/**
 * 财务科目树列表
 */
export const getFinanceSubjectList = () => {
  return http.get("/finance/subject/tree");
};
/**
 * 添加财务科目
 */
export const addFinanceSubject = (data: financeSubjectsParams) => {
  return http.post("/finance/subject/add", data);
};

/**
 * 编辑财务科目
 */
export const editFinanceSubject = (data: financeSubjectsParams) => {
  return http.post("/finance/subject/edit", data);
};
/**
 * 删除财务科目
 */
export const delFinanceSubject = (subjectId: string) => {
  return http.get(`/finance/subject/delete/${subjectId}`);
};
/**
 * 报销借款分类树
 */
export const getLoanTree = () => {
  return http.get("/finance/billCategory/tree");
};

/**
 * 新增报销借款分类
 */
export const addLoanCategory = (data: LoanParams) => {
  return http.post("/finance/billCategory/add", data);
};
/**
 * 编辑报销借款分类
 */
export const editLoanCategory = (data: LoanParams) => {
  return http.post("/finance/billCategory/edit", data);
};
/**
 * 删除报销借款分类
 */
export const deleteLoanCategory = (billCategoryId: string) => {
  return http.get(`/finance/billCategory/delete/${billCategoryId}`);
};
/**
 * 报销借款单详情
 */
export const getLoanCategoryDetail = (billCategoryId: string) => {
  return http.get(`/finance/billCategory/detail/${billCategoryId}`);
};
/**
 * OA表单列表
 */
export const getOaFormList = (params: { modelName?: string; groupId: number }) => {
  return http.get("/process/model/list/byUser", params);
};
/**
 * 财务单据列表
 */
export const getInvoicesList = () => {
  return http.get<InvoicesList[]>("/finance/slipType/list");
};
/**
 * 配置财务单据
 */
export const configInvoices = (slipType: number, data: { [key: string]: approves[] }) => {
  return http.post(`/finance/slipType/config/${slipType}`, data);
};
/**
 * 获取可配置的科目列表
 */
export const getConfigSubjectList = () => {
  return http.get("/finance/subject/configurableSubject");
};
/**
 * 其他首款分类
 */
export const getOtherCategoryTree = () => {
  return http.get("/finance/billCategory/other/tree");
};

/**
 * 流程配置-获取业务类型
 */
export const businessType = () => {
  return http.get(`/crm/busTaskTemplate/busType`);
};
/**
 * 发包配置-施工节点
 */
export const StageTaskList = (busTypeId: string, params: any) => {
  return http.get(`/crm/build/taskTemplate/getBuildStageTaskList/${busTypeId}`, params);
};

/**
 * 流程配置-获取任务列表table数据
 */
export const taskList = (busTypeId: string, params: any) => {
  return http.get(`/crm/busTaskTemplate/getStageTaskList/${busTypeId}`, params);
};
/**
 * 流程配置-获取业务类型（原客户画像）下的阶段
 */
export const stageOptions = () => {
  return http.get(`/crm/busTaskTemplate/stageList`);
};

/**
 * 流程配置-添加阶段
 */

export const addStage = (busTypeId: string, stageId: string) => {
  return http.post(`/crm/busTaskTemplate/addStage/${busTypeId}/${stageId}`);
};

/**
 * 流程配置-获取前置条件-前置流程
 */

export const preProcess = (busTypeId: string, stageType: string | number) => {
  return http.get(`/crm/busTaskTemplate/list/${busTypeId}?stageType=${stageType}`);
};

/**
 * 流程配置-新增普通业务流程任务
 */

export const addBusTaskTemplate = (data: any) => {
  return http.post(`/crm/busTaskTemplate/add`, data);
};

/**
 * 流程配置-编辑普通业务流程任务
 */

export const editBusTaskTemplate = (taskSettingId:string,data:any) => {

  return http.post(`/crm/busTaskTemplate/update/${taskSettingId}`,data);
};

/**
 * 流程配置-获取流程详情
 */
export const processDetail = (taskSettingId: string) => {
  return http.get(`/crm/busTaskTemplate/detail/${taskSettingId}`);
};

/**
 * 流程配置-修改流程状态
 */

export const setTaskStatus = (taskSettingId: string, status: string | number) => {
  return http.put(`/crm/busTaskTemplate/setStatus/${taskSettingId}?status=${status}`);
};

/**
 * 流程配置-删除任务
 */
export const deleteProcessTask = (taskSettingId: string) => {
  return http.deleteMethod(`/crm/busTaskTemplate/delete/${taskSettingId}`);
};

/**
 * 流程配置-删除阶段
 */
export const deleteStageTask = (busTypeId: string, stageId: string) => {
  return http.deleteMethod(`/crm/busTaskTemplate/deleteStage/${busTypeId}/${stageId}`);
};

/**
 * 任务模板-获取任务详情
 */
export const taskDetail = (taskSettingId: string) => {
  return http.get(`/crm/task/template/taskSettings/detail/${taskSettingId}`);
};
/**
 * 整改模板-获取任务详情1
 */
export const rectificationDetail = (taskSettingId: string) => {
  return http.get(`/crm/reform/template/taskSettings/detail/${taskSettingId}`);
};




/**
 * 预收款分类树
 */
export const getAdvancePaymentTree=()=>{
  return http.get("/finance/billCategory/earnest/tree");
}
